from odoo import api, fields, models


class EvenOut(models.Model):
    _name = "event.out"

    event_id = fields.Char(
        string='境外发生的药品不良反应/事件报告表编号',
        index=True,
        readonly=True,
    )

    @api.model
    def create(self, vals):
        vals['event_id'] = self.env['ir.sequence'].next_by_code('event.out') or ''
        return super(EvenOut, self).create(vals)

    name = fields.Char(
        default='境外不良反应报告详情'
    )
    feel_out_ids = fields.Many2many(
        'feel.out',
        'event_id',
        string='境外不良反应事件'
    )
    vaccine = fields.Many2one(
        'vaccine.information.entering',
        string='疫苗'
    )
    vaccine_en = fields.Char(
        related='vaccine.name_en',
        readonly=True,
        string='疫苗英文名',
        store=True
    )
    vaccine_usual = fields.Char(
        related='vaccine.name_usual',
        readonly=True,
        string='疫苗通用中文名',
        store=True
    )
    vaccine_usual_en = fields.Char(
        related='vaccine.name_usual_en',
        readonly=True,
        string='疫苗通用英文名',
        store=True
    )
    vaccine_standard = fields.Selection(
        related='vaccine.standard',
        readonly=True,
        string='剂量',
        store=True
    )
    report_company = fields.Many2one(
        'vaccine.organization',
        string='报告单位',
        required=True
    )
    person = fields.Many2one(
        'res.users',
        string='联系人',
        required=True
    )
    tele = fields.Char(
        related='person.mobile',
        readonly=True,
        string='电话',
        store=True
    )
    date = fields.Date(
        string='报告日期',
        default=lambda self: fields.Date.today(),
        required=True
    )
